import React, { useState,createContext,useContext } from "react";


const CountContext = createContext();

function Counter() {
    let count = useContext(CountContext);
    return (
        <h1>
            {count}
        </h1>
    )
}

function Example() {

    const [count,setCount] = useState(0);

    return (
        <div>
            <div>
                <div>{count}</div>
                <button onClick={ () => setCount(count+1)}>+ 1</button>
            </div>

            <CountContext.Provider value={count}>
                <Counter />
            </CountContext.Provider>
        </div>
        
    )
}

export default Example;